<template>
	<view>
		<view v-if="carList.length >=1">
			<!-- 顶部收货地址 -->
			<my-address></my-address>
			<!-- 购物车信息区 -->
			<view class="cart-totie">
				<uni-icons type="shop" size="20" />
				<text class="cart-title">购物车</text>
			</view>
			<view class="zhobu">
				<uni-swipe-action>
					<block v-for="(item,index) in carList" :key="index">
						<uni-swipe-action-item :right-options="options" @click="shanchuList(index)">
							<my-goods :goolistobj="item" :ishow="true"></my-goods>
						</uni-swipe-action-item>
					</block>
				</uni-swipe-action>
			</view>
			<!-- 结算组件 -->
			<my-settle></my-settle>
		</view>
		<!-- 购物车为空的状态 -->
		<view class="kong" v-else>
			<view class="konghezi">
				<image class="img" src="/static/userImg.png"></image>
				<text class="kongname">空空如也~</text>
			</view>
		</view>
	</view>
</template>

<script>
	import badgeMix from '@/mixins/tabbar-badge.js'
	import {
		mapState,
		mapGetters
	} from 'vuex'
	export default {
		mixins: [badgeMix],
		data() {
			return {
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#C00000'
					}
				}],
			};
		},
		computed: {
			...mapState({
				carList: state => state.cart.cartData
			}),
		},
		onShow() {},
		methods: {
			//商品删除
			shanchuList(index) {
				uni.showModal({
					content: '确认删除该商品嘛？',
					confirmText: '确定',
					cancelText: '取消',
					success: ({
						confirm
					}) => {
						if (confirm) {
							this.$store.commit('addgetlistdiet', index)
							uni.showToast({
								title: '删除成功',
								icon: 'success',
								mask: true
							})
						} else {
							uni.showToast({
								title: '删除已取消',
								icon: 'error',
								mask: true
							})
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.zhobu {
		padding-bottom: 55px;
	}

	.cart-totie {
		height: 40px;
		display: flex;
		align-items: center;
		border-bottom: 1px solid #dadada;
		padding: 0 5px;

		.cart-title {
			margin-left: 5px;
		}
	}
	.kong{
		width: 100%;
		height: 500px;
		display: flex;
		justify-content: center;
		align-items: center;
		.konghezi{
			display: flex;
			flex-direction: column;
			align-items: center;
			.img{
				border-radius: 10px;
				width: 200px;
				height: 150px;
			}
			.kongname{
				margin-top: 10px;
				color: #a5a5a5;
			}
		}
	}
</style>
